<template>
	<view>
		<view class="pt-40 pb-40 pl-40 pr-40 bg-g flex items-center" v-if="user === null" @click="$goRoute.goUrl('/pages/login/login')">
			<image src="../../static/images/avatar.png" mode="" style="width: 100rpx;height: 100rpx;border-radius: 50%;"></image>
			<view class="ml-20 font-white">
				<view>登录/注册</view>
				<view class="font-24 mt-20">登录后显示</view>
			</view>
		</view>
		<view class="pt-40 pb-40 pl-40 pr-40 bg-g flex items-center" v-if="user !== null" @click="goInfo()">
			<image src="../../static/images/avatar.png" mode="" style="width: 100rpx;height: 100rpx;border-radius: 50%;"></image>
			<view class="ml-20 font-white">
				<view>{{user.username}}</view>
				<view class="font-24 mt-20" v-if="user.type === 0">求职者</view>
				<view class="font-24 mt-20" v-else>东营XX有限公司</view>
			</view>
		</view>
		<view class="p-20 mt-20" v-if="type === 0">
			<view class="flex items-center space-between pt-30 pb-30 bg-white border-radius">
				<view style="width: 25%;" class="text-center" @click="goDetail('/pages/user/resume')">
					<uni-icons custom-prefix="iconfont" type="icon-yanghu" size="30" color="#46B4B1"></uni-icons>
					<view class="font-24 mt-20">简历管理</view>
				</view>
				<view style="width: 25%;" class="text-center" @click="refush(0)">
					<uni-icons custom-prefix="iconfont" type="icon-shuaxin" size="30" color="#FF7700"></uni-icons>
					<view class="font-24 mt-20">刷新简历</view>
				</view>
				<view style="width: 25%;" class="text-center" @click="goDetail('/pages/user/collective?type=0')">
					<uni-icons custom-prefix="iconfont" type="icon-favourited" size="30" color="#00B1FF"></uni-icons>
					<view class="font-24 mt-20">职位收藏</view>
				</view>
				<view style="width: 25%;" class="text-center" @click="goDetail('/pages/user/collective?type=1')">
					<uni-icons custom-prefix="iconfont" type="icon-guanzhuxuanzhong" size="30" color="#FF0022"></uni-icons>
					<view class="font-24 mt-20">我的关注</view>
				</view>
			</view>
		</view>
		<view class="p-20 mt-20" v-if="type === 1">
			<view class="flex items-center space-between pt-30 pb-30 bg-white border-radius">
				<view style="width: 25%;" class="text-center" @click="goDetail('/pages/job/forms')">
					<uni-icons custom-prefix="iconfont" type="icon-fabuguanli" size="30" color="#46B4B1"></uni-icons>
					<view class="font-24 mt-20">职位发布</view>
				</view>
				<view style="width: 25%;" class="text-center" @click="refush(1)">
					<uni-icons custom-prefix="iconfont" type="icon-shuaxin" size="30" color="#FF7700"></uni-icons>
					<view class="font-24 mt-20">一键刷新</view>
				</view>
				<view style="width: 25%;" class="text-center" @click="goDetail('/pages/job/job')">
					<uni-icons custom-prefix="iconfont" type="icon-yingxiaoguanli-dingdanguanli" size="30" color="#00B1FF"></uni-icons>
					<view class="font-24 mt-20">职位管理</view>
				</view>
				<view style="width: 25%;" class="text-center" @click="goDetail('/pages/user/attention?type=1')">
					<uni-icons custom-prefix="iconfont" type="icon-guanzhuxuanzhong" size="30" color="#FF0022"></uni-icons>
					<view class="font-24 mt-20">我的关注</view>
				</view>
			</view>
		</view>
		<view class="pl-20 pr-20 pt-20" @click="goDetail('/pages/user/matching/matching')" v-if="type === 0">
			<view class="flex space-between items-center bg-white p-30 border-radius">
				<view class="flex items-center">
					<uni-icons custom-prefix="iconfont" type="icon-pipei" size="20"></uni-icons>
					<view class="font-24 ml-20">智能匹配</view>
				</view>
				<uni-icons custom-prefix="iconfont" type="icon-xiangyou" size="16"></uni-icons>
			</view>
		</view>
		<view class="pl-20 pr-20 pt-20" @click="goDetail('/pages/user/matching/users')" v-if="type === 1">
			<view class="flex space-between items-center bg-white p-30 border-radius">
				<view class="flex items-center">
					<uni-icons custom-prefix="iconfont" type="icon-pipei" size="20"></uni-icons>
					<view class="font-24 ml-20">智能匹配</view>
				</view>
				<uni-icons custom-prefix="iconfont" type="icon-xiangyou" size="16"></uni-icons>
			</view>
		</view>
		
		<view class="pl-20 pr-20 pt-20" @click="goDetail('/pages/company/form')" v-if="type === 1">
			<view class="flex space-between items-center bg-white p-30 border-radius">
				<view class="flex items-center">
					<uni-icons type="home" size="20"></uni-icons>
					<view class="font-24 ml-20">公司信息管理</view>
				</view>
				<uni-icons custom-prefix="iconfont" type="icon-xiangyou" size="16"></uni-icons>
			</view>
		</view>
		<view class="pl-20 pr-20 pt-20" @click="goDetail('/pages/job_work/userAdd')">
			<view class="flex space-between items-center bg-white p-30 border-radius">
				<view class="flex items-center">
					<uni-icons type="staff" size="20"></uni-icons>
					<view class="font-24 ml-20">零活零工管理</view>
				</view>
				<uni-icons custom-prefix="iconfont" type="icon-xiangyou" size="16"></uni-icons>
			</view>
		</view>
		<view class="pl-20 pr-20 pt-20" @click="setType">
			<view class="flex space-between items-center bg-white p-30 border-radius">
				<view class="flex items-center">
					<uni-icons custom-prefix="iconfont" type="icon-qiehuanyonghu" size="20"></uni-icons>
					<view class="font-24 ml-20">角色切换</view>
				</view>
				<uni-icons custom-prefix="iconfont" type="icon-xiangyou" size="16"></uni-icons>
			</view>
		</view>
		<view class="pl-20 pr-20 pt-20" @click="goDetail('/pages/user/feedback')">
			<view class="flex space-between items-center bg-white p-30 border-radius">
				<view class="flex items-center">
					<uni-icons custom-prefix="iconfont" type="icon-wentifankui" size="20"></uni-icons>
					<view class="font-24 ml-20">留言反馈</view>
				</view>
				<uni-icons custom-prefix="iconfont" type="icon-xiangyou" size="16"></uni-icons>
			</view>
		</view>
		<view class="pl-20 pr-20 pt-20" @click="goApp">
			<view class="flex space-between items-center bg-white p-30 border-radius">
				<view class="flex items-center">
					<uni-icons type="weixin" size="20"></uni-icons>
					<view class="font-24 ml-20">前往河口人才智能云</view>
				</view>
				<uni-icons custom-prefix="iconfont" type="icon-xiangyou" size="16"></uni-icons>
			</view>
		</view>
		<view class="pl-20 pr-20 pt-20" @click="loginOut">
			<view class="flex space-between items-center bg-white p-30 border-radius">
				<view class="flex items-center">
					<uni-icons custom-prefix="iconfont" type="icon-tuichudenglu" size="20"></uni-icons>
					<view class="font-24 ml-20">退出登录</view>
				</view>
				<uni-icons custom-prefix="iconfont" type="icon-xiangyou" size="16"></uni-icons>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: null,
				type: 0
			}
		},
		onShow() {
			const user = uni.getStorageSync('userInfo')
			if (user) {
				this.user = user
				this.getUserType()
			} else {
				this.user = null
			}
		},
		methods: {
			goInfo() {
				if (this.type === 1) {
					this.$goRoute.goUrl('/pages/user/hrinfo')
				}
			},
			goApp() {
				uni.navigateToMiniProgram({
				  appId: 'wx1a8136dd0c14d8e3',
				  path: 'pages/index/index',
				  success(res) {
				    // 打开成功
				  }
				})
			},
			getUserType() {
				const user = uni.getStorageSync('userInfo')
				if (user) {
					this.user = user
					this.type = user.type
					if (user.type === 1) {
						uni.setTabBarItem({
						  index: 1,
						  text: '人才',
						  iconPath: 'static/images/t-2.png',
						  selectedIconPath: 'static/images/t-2-s.png'
						})
					}
				}
			},
			loginOut() {
				if (this.user === null) {
					return false
				}
				const _this = this
				this.$tips.showModal('是否退出登录？', () => {
					_this.$tips.showConfirmModal('退出登录成功', () => {
						uni.clearStorageSync()
						uni.switchTab({
							url: '/pages/index/index'
						})
					})
				})
			},
			setType() {
				if (this.user === null) {
					this.$tips.showConfirmModal('请先登录')
					return false
				}
				const _this = this
				if (this.user.type === 0) {
					this.$tips.showModal('是否切换为招聘人员？', () => {
						_this.$tips.showConfirmModal('切换成功', () => {
							uni.setStorageSync('userInfo', {
								username: '小程序用户',
								type: 1
							})
							_this.user = {
								username: '小程序用户',
								type: 1
							}
							_this.type = 1
						})
					})
				} else {
					this.$tips.showModal('是否切换为求职人员？', () => {
						_this.$tips.showConfirmModal('切换成功', () => {
							uni.setStorageSync('userInfo', {
								username: '小程序用户',
								type: 0
							})
							_this.user = {
								username: '小程序用户',
								type: 0
							}
							_this.type = 0
						})
					})
				}
			},
			goDetail(url) {
				if (this.user === null) {
					this.$tips.showConfirmModal('请先登录')
					return false
				}
				uni.navigateTo({
					url: url
				})
			},
			refush(type) {
				if (this.user === null) {
					this.$tips.showConfirmModal('请先登录')
					return false
				}
				const _this = this
				if (type === 0) {
					this.$tips.showModal('是否刷新简历？', () => {
						_this.$tips.showConfirmModal('刷新成功', () => {})
					})
				} else {
					this.$tips.showModal('是否刷新职位信息？', () => {
						_this.$tips.showConfirmModal('刷新成功', () => {})
					})
				}
			}
		}
	}
</script>

<style lang="less">
	page {
		background-color: #f6f6f6;
	}
</style>
